import { inject, Injectable } from '@angular/core';
import { ACLService } from '@delon/acl';
import { _HttpClient } from '@delon/theme';
import { NzSafeAny } from 'ng-zorro-antd/core/types';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { Api } from '../api/api';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { ResponseCode } from '../response.code';
@Injectable({
  providedIn: 'root'
})
export class AbilityService {
  protected readonly http = inject(_HttpClient);
  protected readonly aclService = inject(ACLService);

  allAbilities: NzSafeAny = {};

  initAbilities() {
    // TODO 权限
    // const allAbilitiesStr = localStorage.getItem('page_abilities') || null;
    // if (!allAbilitiesStr) {
    //   return;
    // }
    // this.allAbilities = JSON.parse(allAbilitiesStr);
    // this.http.get(`${Api.BaseAntMenuApi}/role/abilities`).subscribe((res: NzSafeAny) => {
    //   if (res && res.code === ResponseCode.SUCCESS) {
    //     if (res.data) {
    //       this.allAbilities = res.data;
    //       localStorage.setItem('page_abilities', JSON.stringify(res.data));
    //     }
    //   }
    // });
  }

  // eslint-disable-next-line @typescript-eslint/no-unused-vars
  filterAbility(router: string) {
    // TODO 权限
    // if (this.allAbilities && this.allAbilities[router]) this.aclService.setAbility(this.allAbilities[router]);
    // else
    //   this.http.get(`${Api.BaseAntMenuApi}/role/abilities`).subscribe((res: NzSafeAny) => {
    //     if (res && res.code === ResponseCode.SUCCESS) {
    //       if (res.data) {
    //         this.allAbilities = res.data;
    //         const rolePermission = res.data[router];
    //         if (rolePermission) this.aclService.setAbility(rolePermission);
    //       }
    //     }
    //   });
    this.aclService.setAbility(['add', 'delete', 'query', 'edit']);
  }
  initUserAbility() {
    // TODO 权限
    // this.initAbilities();
  }

  clear(): void {
    this.aclService.setAbility([]);
  }
}
